/*************************************************************************
	> File Name: clock_nanosleep.c
	> Author: Angel Criss
	> Blog: blog.abbycin.tk 
	> Created Time: Sat 05 Jul 2014 03:36:08 PM CST
 ************************************************************************/
/*
 * 仅仅作为一个高精度睡眠,不能睡眠期间不能接受任何信号
 * 手册页中描述:
 *              function shall cause the current thread to be suspended from
 *              execution until either the time value of clock specified by
 *              the 'rqtp'(here is req) argument has elaped, or a signal is delivered to the 
 *              calling thread and its action is to invoke a signal-cathing 
 *              function, or the process is terminated.
 *和nanosleep 比较

#define _XOPEN_SOURCE 600
#include<stdio.h>
#include<time.h>
#include<errno.h>
#include<stdlib.h>
#include<unistd.h>

int main(int argc,char *argv[])
{
    struct timespec req; // declare start time
    struct timespec rem; // declare remain time

/*    if(clock_gettime(CLOCK_REALTIME,&req)==-1)
    {
        perror("gettime:");
        _exit(errno);
    }
    */
    req.tv_sec=10; // set timer expiration to 10s 相对时间
    req.tv_nsec=0; // set to zero

    if(clock_nanosleep(CLOCK_REALTIME,0,&req,&rem)!=0)
    {
        perror("clock_nanosleep:");
        _exit(errno);
    }// 0 :相对时间 TIMER_ABSTIMER: 绝对时间(此时不再需要rem)

}
